﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>地图距离查询</title>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? document.location.protocol + "//" + document.location.host : "http://support.supermap.com.cn:8090";
    var map, circleMarker, resultLayer,
        url = host + "/iserver/services/map-world/rest/maps/World";
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: [20, 100],
        maxZoom: 18,
        zoom: 3
    });
    L.supermap.tiledMapLayer(url).addTo(map);
    circleMarker = L.circleMarker([30, 104], {color: 'red'}).addTo(map);
    circleMarker.bindPopup('distance = 10').openPopup();
    query();

    function query() {
        var param = new SuperMap.QueryByDistanceParameters({
            queryParams: {name: "Capitals@World.1"},
            distance: 10,
            geometry: circleMarker
        });
        L.supermap
            .queryService(url)
            .queryByDistance(param, function (serviceResult) {
                var result = serviceResult.result;
                resultLayer = L.geoJSON(result.recordsets[0].features).addTo(map);
            });
    }
</script>
</body>
</html>